﻿namespace AlgorithmInterview.Chapter02._07;

public class MyQueue
{
    private List<User> q = new List<User>();

    /// <summary>
    /// 进入队列尾部
    /// </summary>
    /// <param name="u"></param>
    public void EnQueue(User u)
    {
        u.Seq = q.Count + 1;
        q.Add(u);
    }

    /// <summary>
    /// 队头出队列
    /// </summary>
    public void DeQueue()
    {
        q.First();
        DeQueue(q.First());
    }

    /// <summary>
    /// 队列中的人随机离开
    /// </summary>
    /// <param name="u"></param>
    public void DeQueue(User u)
    {
        if (u != null)
        {
            q.Remove(u);
            UpdateSeq();
        }
    }

    /// <summary>
    /// 出队列后更新队列中每个人的序列
    /// </summary>
    void UpdateSeq()
    {
        int i = 1;
        q.ForEach(p => p.Seq = i++);
    }

    /// <summary>
    /// 打印队列的信息
    /// </summary>
    public void PrintList()
    {
        foreach (var item in q)
        {
            Console.WriteLine(item.ToString());
        }
    }
}